package com.zy.assemble.fragment

import android.content.Intent
import com.zy.activity.BaseListFragment
import com.zy.activity.adapter.FragmentListBean
import com.zy.activity.adapter.ShowType
import com.zy.test.animation.AnimationMenuActivity
import com.zy.test.handler.HandlerTestMenuActivity
import com.zy.test.store.StoreMainListActivity
import com.zy.test.widget.ViewTestListMainActivity
import com.zy.test.widget.WidgetListMainActivity
import java.util.ArrayList

class AndroidFragment : BaseListFragment() {
    override fun init(list: ArrayList<FragmentListBean>) {
        list.add(FragmentListBean(ShowType.HEAD, "UI组件"))
        list.add(FragmentListBean(ShowType.COMMON, "UI组件", "UI组件", 1))
        list.add(FragmentListBean(ShowType.COMMON, "View", "Android View", 4))
        list.add(FragmentListBean(ShowType.COMMON, "动画", "动画", 2))
        list.add(FragmentListBean(ShowType.COMMON, "Handler", "消息处理机制", 3))
        list.add(FragmentListBean(ShowType.COMMON, "存储", "存储", 5))
    }

    override fun clickItem(bean: FragmentListBean) {
        when (bean.code) {
            1 -> {
                startAT(WidgetListMainActivity::class.java)
            }
            4 -> {
                startAT(ViewTestListMainActivity::class.java)
            }
            2 -> {
                startAT(AnimationMenuActivity::class.java)
            }
            3 -> {
                startAT(HandlerTestMenuActivity::class.java)
            }
            5 -> {
                startAT(StoreMainListActivity::class.java)
            }
        }
    }

    private fun <T> startAT(classS: Class<T>) {
        requireActivity().startActivity(Intent(requireContext(), classS))
    }

    companion object {
        fun newInstance() = AndroidFragment()
    }
}